package com.homeproject.trailservice.service.grouppurchase.impl;

import com.homeproject.trailservice.dal.DelivererRepository;
import com.homeproject.trailservice.dal.DeliveryCompanyRepository;
import com.homeproject.trailservice.domain.Deliverer;
import com.homeproject.trailservice.domain.DeliveryCompany;
import com.homeproject.trailservice.service.grouppurchase.DeliveryCompanyManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Optional;

@Component
public class DeliveryCompanyManagerImpl implements DeliveryCompanyManager {
    @Autowired
    private DeliveryCompanyRepository deliveryCompanyRepository;

    @Autowired
    private DelivererRepository delivererRepository;


    @Override
    public Optional<DeliveryCompany> findDeliveryCompanyByDeliverer(String delivererName) {
        List<DeliveryCompany> deliveryCompanies =
                delivererRepository.findDeliveryCompanyByName(delivererName);
        return CollectionUtils.isEmpty(deliveryCompanies)?Optional.empty():deliveryCompanies.stream().findFirst();
    }

    @Override
    public List<Deliverer> findDelivererListByDelivererCompany(String deliveryCompanyName) {
        return null;
    }
}
